require_relative 'request_info_table'
require_relative 'request_history_table'

class RequestPage

  def initialize(b)
    @b = b
  end

  def get_request
    return if request_not_found?

    request_info_table = RequestInfoTable.new @b.tables[1]
    request_history_table = RequestHistoryTable.new @b.tables[3]

    r = { id: request_id }
    r.merge! request_info_table.get_request_info
    r.merge! request_history_table.get_resolution_info
    r
  end

  private

  def request_id
    @b.text[/Request #(\d+)/, 1]
  end

  def request_not_found?
    @b.text =~ /Request #\d+ not found/
  end

end